#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# ======================================================
# @File:      : test560
# @Author     : forward_huan
# @Date       : 2024/11/16 22:03
# @Desc       :
# ======================================================
from typing import List


class Solution:
    def subarraySum(self, nums: List[int], k: int) -> int:
        count, pre = 0, 0
        mp = {0: 1}
        for i in range(len(nums)):
            pre += nums[i]
            if (pre - k) in mp:
                count += mp[pre - k]
            mp[pre] = mp.get(pre, 0) + 1
            print(mp)
        return count


# print(Solution().subarraySum(nums=[1, 1, 1], k=2))
# print(Solution().subarraySum(nums=[1, 2, 3], k=3))
# print(Solution().subarraySum(nums=[1], k=3))
# print(Solution().subarraySum(nums=[-1, -1, 1], k=1))
# print(Solution().subarraySum(nums=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], k=0))
print(Solution().subarraySum(nums=[3, 4, 7, 2, -3, 1, 4, 2], k=7))
